home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
basic2
/
pro15
/
typer.bas
< prev
next >
Wrap
BASIC Source File
|
1987-10-11
|
3KB
|
109 lines
'*****************************************************************************
'Copyright (c) 1987 Marcel Madonna
'TYPER.BAS is an example of redirection. To compile it, at the DOS prompt
' type:
' qb typer /l qbdos.exe;
' link typer;
' del typer.obj
'To execute TYPER just type "TYPER" at the DOS prompt and you will be prompted
'for a file name to type on the monitor. This is a pretty simple program so
'
' USE A REAL FILE NAME OR ELSE THIS PROGRAM WILL ABORT
' USE AN ASCII FILE (LICENSE.DOC ON THE DISTRIBUTION DISKETTE
' WILL WORK JUST FINE)
'To route the output to a printer instead of the monitor, type:
' TYPER /LPT1
'To route output to a file, type:
' TYPER /TEXTFILE.DAT
'*****************************************************************************
';Usage - Call Dosred(Device%, FileSpec$, Rc%)
'; Device% 0 - Stdin
'; 1 - Stdout
'; 2 - Stderr (not redirectable)
'; 3 - AUX (standard auuxilliary device)
'; 4 - PRN (standard list device)
'; FileSpec$ - name of file or device
'; null - reset handle
'; chr$(255) - close handle and exit
'; Rc% 0 - good return
'; 6 - handle already closed
'; 255 - error
'*****************************************************************************
Dim In.Array$(2000)
If Len(Command$) = 0 then
Red% = 0
Else
Red% = -1
Pipe.Char$ = Left$(Command$,1)
Red.File$ = Right$(Command$,Len(Command$)-1)
While Left$(Red.File$,1) = Space$(1) 'Remove leading blanks
Red.File$ = Right$(Red.File$,Len(Red.File$)-1)
Wend
While Right$(Red.File$,1) = Space$(1) 'Remove trailing blanks
Red.File$ = Left$(Red.File$,Len(Red.File$)-1)
Wend
End if
Print Red.file$
Locate 1,1
Print "You are being prompted for a file name."
Print "Because this is a sample program only, I need"
Print "a real file name or else this program will "
Print "ABORT. LICENSE.TXT on the distribution diskette"
Print "will work just fine."
Print
Line Input "Give me a file name please: ", File.Nam$
Cls
Open File.Nam$ For Input As #1 'Open and read the entire file
While Not Eof(1)
If x% >= Ubound(In.Array$) then
Line Input #1, In.Array$(Ubound(In.Array$))
Else
x% = x% + 1
Line Input #1, In.Array$(x%)
End if
Wend
Close #1
Stdin% = 0
Stdout% = 1
Stdaux% = 3
Stdlist% = 4
' Redirect device here
If Red% then
Call DosRed(Stdout%, Red.File$ + chr$(0), Rc%)
If Rc% <> 0 then
Print "Error", Rc%
System
End if
End if
' Print file here
' Use 'print' statements to print to both CON and Red.File$
' Use DosChout to print to only Red.File$
For y% = 1 to x%
Call Doschout(In.Array$(y%)+chr$(10)+chr$(13))
' Print In.Array$(y%)
next
' Reset device to original
If Red% then Call Dosred(Stdout%,"",Rc%) 'Reset device